import 'package:flutter/material.dart';
import 'package:flutter_demo/ui/pages/status/data/share_data_notifier.dart';
import 'package:flutter_demo/ui/pages/status/provider/change/a2_page_widget.dart';
import 'package:flutter_demo/ui/pages/status/provider/change/b2_page_widget.dart';
import 'package:provider/provider.dart';

//参考文档 https://blog.csdn.net/Lastdoggod/article/details/125955791
class ChangeNotifierProviderTestWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _ChangeNotifierProviderTestState();
}

class _ChangeNotifierProviderTestState
    extends State<ChangeNotifierProviderTestWidget> {
  @override
  Widget build(BuildContext context) {
    /**
     * 它跟Provider组件不同，ChangeNotifierProvider会监听模型对象的变化，而且当数据改变时，它会重建消费者。
     * 共享数据必须继承 ChangeNotifier
     */
    return ChangeNotifierProvider<ShareDataNotifier>(
      ///配置共享数据
      create: (context) {
        return ShareDataNotifier(nickname: "tc ...", level: 0);
      },
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: const [A2PageWidget(), B2PageWidget()],
      ),
    );
  }
}
